ChatGPT是一個由OpenAI訓練的大型生成式語言模型,其中常用的有GPT-3、GPT-3.5、GPT-4版本,GPT-3 在半監督式模式下接受訓練,而 GPT-3.5 是 GPT-3 的微調版。GPT-4 是多模態模型,可以解析圖像和文本。
此次使用的是免費的 GPT-3.5,試著用來幫助我學習CPE(大學程式能力檢定)的一星題庫。
CPE(大學程式能力檢定)目標是在評估學生在程式設計和計算機科學領域的能力。參加者需要在限定的時間內解決一系列的程式設計問題,一場測試中包含了初級、中級和高級的難度級別題目。在未來30天內,我將利用ChatGPT協助我解答CPE的一星題庫。
一顆星選集出自大學程式能力檢定網址:
https://cpe.cse.nsysu.edu.tw/environment.php#starList
NO. | 題目 | 題號 |
---|---|---|
1. | Vito's family | (CPE10406, UVA10041) |
2. | Hashmat the brave warrior | (CPE10407, UVA10055) |
3. | Primary Arithmetic | (CPE10404, UVA10035) |
4. | The 3n + 1 problem | (CPE10400, UVA100) |
5. | You can say 11 | (CPE10460, UVA10929) |
6. | Bangla Numbers | (CPE10414, UVA10101) |
7. | List of Conquests | (CPE21924, UVA10420) |
字元與字串 | ||
8. | What's Cryptanalysis? | (CPE10402, UVA10008) |
9. | Decode the Mad man | (CPE10425, UVA10222) |
10. | Problem J: Summing Digits | (CPE10473, UVA11332) |
11. | Common Permutation | (CPE10567, UVA10252) |
12. | Rotating Sentences | (CPE21914, UVA490) |
13. | TeX Quotes | (CPE22131, UVA272) |
數學計算 | ||
14 . | A - Doom's Day Algorithm | (CPE22801, UVA12019) |
15 . | Jolly Jumpers | (CPE10405, UVA10038) |
16 . | What is the Probability!! | (CPE10408, UVA10056) |
17 . | The Hotel with Infinite Rooms | (CPE10417, UVA10170) |
18 . | 498’ | (CPE10431, UVA10268) |
19 . | Odd Sum | (CPE10453, UVA10783) |
20 . | Beat the Spread! | (CPE10454, UVA10812) |
21 . | Symmetric Matrix | (CPE10478, UVA11349) |
22 . | Square Numbers | (CPE10480, UVA11461) |
23 . | B2-Sequence | (CPE23621, UVA11063) |
24 . | Back to High School Physics | (CPE10411, UVA10071) |
進位制轉換 | ||
25 . | An Easy Problem! | (CPE10413, UVA10093) |
26 . | Fibonaccimal Base | (CPE10401, UVA948) |
27 . | Funny Encryption Method | (CPE10403, UVA10019) |
28 . | Parity | (CPE10461, UVA10931) |
29 . | Cheapest Base | (CPE10466, UVA11005) |
質數、因數與倍數 | ||
30 . | Hartals | (CPE10517, UVA10050) |
31 . | All You Need Is Love! | (CPE10421, UVA10193) |
32 . | Divide, But Not Quite Conquer! | (CPE10419, UVA10190) |
33 . | Simply Emirp | (CPE10428, UVA10235) |
34 . | 2 the 9s | (CPE10458, UVA10922) |
35 . | GCD | (CPE11076, UVA11417) |
幾何與座標 | ||
36 . | Largest Square | (CPE10456, UVA10908) |
37 . | Satellites | (CPE10424, UVA10221) |
38 . | Can You Solve It? | (CPE10447, UVA10642) |
39 . | Fourth Point!! | (CPE10566, UVA10242) |
排序與中位數 | ||
40 . | A mid-summer night’s dream | (CPE10409, UVA10057) |
41 . | Tell me the frequencies! | (CPE10410, UVA10062) |
42 . | Train Swapping | (CPE22811, UVA299) |
43 . | Hardwood Species | (CPE10426, UVA10226) |
模擬 | ||
44 . | Minesweeper | (CPE10418, UVA10189) |
45 . | Die Game | (CPE11019, UVA10409) |
46 . | Eb Alto Saxophone Player | (CPE11020, UVA10415) |
47 . | Mutant Flatworld Explorers | (CPE23641, UVA118) |
48 . | Cola | (CPE11067, UVA11150) |
其他 | ||
49 . | Sort! Sort!! and Sort!!! | (CPE11069, UVA11321) |
ChatGPT 問題輸入:
大學程式能力檢定 UVA10041 Vito's family 問題的中文與英文描述,包含錯誤處理和邊界檢查的完整C++範例程式碼,用於解決UVA10041問題,以及解題思路的解釋
題目描述:
中文:Vito's family 是一個住在古老村莊的家族。當Vito的家人想要回家時,由於村莊的道路特殊,每個家庭成員必須站在村莊中的某個位置。村莊中共有N個位置,這些位置排列在一條直線上,第i個位置的坐標為Xi。當一家人的每個成員都站在不同的位置時,稱為這個位置的「家庭值」。您的目標是找到一個位置,使得所有家庭成員到達該位置的距離總和最小。請找出這個最小的距離總和。
英文:Vito's family is a family living in an ancient village. When Vito's family members want to return home, due to the special layout of the village's roads, each family member must stand at a certain position in the village. There are a total of N positions in the village, arranged in a straight line, with the coordinates of the i-th position being Xi. When each member of a family stands at a different position, the "family value" of that position is defined. Your goal is to find a position such that the sum of distances for all family members to reach that position is minimized. Find this minimum sum of distances.
範例程式碼:
以下是一個C++的範例程式碼,用於解決UVA10041問題,並包含錯誤處理和邊界檢查。
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int N;
cin >> N;
vector<int> positions(N);
for (int i = 0; i < N; ++i) {
cin >> positions[i];
}
// Sort the positions in ascending order
sort(positions.begin(), positions.end());
// Calculate the median position
int median = positions[N / 2];
// Calculate the sum of distances to the median position
int sumDistances = 0;
for (int i = 0; i < N; ++i) {
sumDistances += abs(positions[i] - median);
}
cout << sumDistances << endl;
}
return 0;
}
解題思路:
解題思路是找到使得所有家庭成員到達的位置的距離總和最小的位置。為了實現這一點,可以將所有家庭成員的位置進行排序,然後選擇中間位置的值作為最終的目標位置。這樣,對於每個家庭成員的位置,計算其到目標位置的距離並將這些距離相加,從而得到最小的距離總和。在程式碼中,使用sort
函數來對位置進行排序,然後計算中位數位置,最後計算距離總和並輸出結果。
最後,要測試ChatGPT的回答,是不是符合所需,要利用兩個C/C++編輯器分別來試,目前列出https://www.onlinegdb.com/ ,以及Visual Studio Code 試試。